package yja.gzw.app.activity

import android.view.inputmethod.EditorInfo
import android.widget.Toast
import androidx.lifecycle.Observer
import com.google.android.material.tabs.TabLayout
import yja.gzw.app.R
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityTixianBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel
import yja.gzw.app.window.Chicun

class TixianActivity :BaseActivity<Mainviewmodel, ActivityTixianBinding>(R.layout.activity_tixian){

    var money="10"
    var typepay="alipay"
    var account="/uploads/20250214/7da897d5603aaf5b3f92ea4d09af7f7e.jpg"

    val listtab= mutableListOf<String>("提现到支付宝","提现到支付宝")
    val chicun= Chicun()
    override fun onResume() {
        super.onResume()
        viewmodel.onyuerwang(UserData.token)

    }

    override fun initView() {
        chicun.chicun(binding.qian1, 0, 100)
        chicun.chicun(binding.qian2, 0, 100)
        chicun.chicun(binding.qian3, 0, 100)
        chicun.chicun(binding.qian4, 0, 100)
        chicun.chicun(binding.qian5, 0, 100)
        chicun.chicun(binding.qian6, 0, 100)
        chicun.chicunwai(binding.qian1, 0, 0,7, 0)
        chicun.chicunwai(binding.qian2, 7, 0,7, 0)
        chicun.chicunwai(binding.qian3, 7, 0,0, 0)
        chicun.chicunwai(binding.qian4, -375, 110,7, 0)
        chicun.chicunwai(binding.qian5, 7, 110,7, 0)
        chicun.chicunwai(binding.qian6, 7, 65,0, 0)

        binding.shurukuang.setOnEditorActionListener {  v, actionId, event->
            if(actionId==EditorInfo.IME_ACTION_DONE){
                    money=binding.shurukuang.text.toString()

            }

            false
        }

        binding.qian1.setOnClickListener {
            money="10"

        }
        binding.qian2.setOnClickListener {
            money="30"

        }
        binding.qian3.setOnClickListener {
            money="100"

        }
        binding.qian4.setOnClickListener {
            money="200"

        }
        binding.qian5.setOnClickListener {
            money="500"

        }



        binding.tixian.setOnClickListener {




            viewmodel.ontixianwang(UserData.token,mapOf("money" to money,"type" to typepay,"account" to account))


        }

        viewmodel.onyuerwang(UserData.token)
        binding.fanhui.setOnClickListener {
            finish()
        }

        for (s in listtab) {

            val tabss= binding.tabs.newTab()
            binding.tabs.addTab(tabss.setText(s))
        }


        binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener{
            override fun onTabSelected(tab: TabLayout.Tab) {
                if(tab.position==0){
                    typepay="alipay"
                    binding.zhifutu.setImageResource(R.mipmap.zhifubaozhifu)
                    binding.shouquan.text="点击支付宝授权"

                }else{
                    binding.zhifutu.setImageResource(R.mipmap.weixingzhifutu)
                    typepay="wechat"
                    binding.shouquan.text="点击微信授权"
                }


            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }

        })




    }

    override fun dataObservese() {
        viewmodel.ontixian.observe(this, Observer {
            if(it.code==1){
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
                viewmodel.onyuerwang(UserData.token)

            }else{
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()

            }

        })

        viewmodel.onyuer.observe(this, Observer {
            if (it.code == 1) {
                binding.keyongyuer.text = it.data.money.toString()
            } else {
                Toast.makeText(this, it.msg, Toast.LENGTH_SHORT).show()
            }
        })
    }
}